/*
 * OREKIT-X
 * Copyright 2002-2008 CS Communication & Systemes
 * 
 * Parts of this software package have been licensed to CS
 * Communication & Systemes (CS) under one or more contributor license
 * agreements.  See the NOTICE file distributed with this work for
 * additional information.
 *  
 * This is an experimental copy of OREKIT from www.orekit.org.
 * Please use the original OREKIT from orekit.org for normal work
 * unrelated to this research project.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License.  You
 * may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package ore.attitudes;

import ore.Frame;
import ore.PositionVelocity;
import ore.bodies.BodyShape;
import ore.bodies.GeodeticPoint;
import ore.time.AbsoluteDate;

import org.apache.commons.math.geometry.Vector3D;

/**
 * This class handles target pointing attitude law.
 * 
 * This class represents the attitude law where the satellite Z axis
 * is pointing to a ground point target.
 * 
 * The target position and velocity are defined in a body frame
 * specified by the user.  It is important to make sure this frame is
 * consistent.
 * 
 * An instance of this class is immutable.
 *
 * @author V&eacute;ronique Pommier-Maurussane
 */
public class TargetPointing
    extends GroundPointing
{

    /**
     * Target in body frame.
     */
    public final PositionVelocity target;


    /** 
     * Creates a new instance from body frame and target expressed in
     * position/velocity coordinates.
     * 
     * @param bodyFrame Body frame.
     * @param target Target expressed in position/velocity coordinates
     * in body frame.
     */
    public TargetPointing(Frame bodyFrame, PositionVelocity target) {
        super(bodyFrame);
        this.target = target;
    }

    /** 
     * Creates a new instance from body shape and target expressed in
     * geodetic coordinates.
     * @param targetGeo Target defined as a geodetic point in body shape frame
     * @param shape Body shape
     */
    public TargetPointing(GeodeticPoint targetGeo, BodyShape shape) {
        super(shape.getBodyFrame());
        /*
         * Transform target from geodetic coordinates to
         * position-velocity coordinates
         */
        this.target = new PositionVelocity(shape.transform(targetGeo), Vector3D.ZERO);
    }


    /** 
     * Get target expressed in body frame at given date.
     *
     * User should check that position/velocity and frame is
     * consistent with given frame.
     * 
     * @param date computation date.
     * @param pv satellite position-velocity vector at given date in given frame.
     * @param frame frame in which satellite position-velocity is given.
     * 
     * @return Target position/velocity in body frame.
     */
    protected PositionVelocity getTargetInBodyFrame(AbsoluteDate date, PositionVelocity pv, Frame frame){
        return this.target;
    }

}
